<?php
namespace app\admin\controller;


use app\common\model\Menu;
use app\common\model\Roleauthorities;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Controller;


/**
 * 企业管理
 * Class Realdata
 * @package app\gygt\controller
 */
class Test extends Controller
{
    public function testadd()
    {
        $spreadsheet = IOFactory::load('./static/template.xlsx');
// 获取当前活动的工作表(默认是第一个工作表)
        $worksheet = $spreadsheet->getActiveSheet();
// 假设我们要在第3行之后插入3行
        $startNum = 11;
        $startRow = 21;
        $numberOfRowsToInsert = 5;
// 插入行
        for ($i = $numberOfRowsToInsert; $i >= 1; $i--) {
            $worksheet->insertNewRowBefore($startRow + 1, 1);
        }
// 填充数据
        for ($row = $startRow; $row <= $startRow + $numberOfRowsToInsert; $row++) {
            $worksheet->setCellValue('B' . $row, $startNum+($row - $startRow));
        }
// 保存Excel文件
        $writer = new Xlsx($spreadsheet);
        $files = time().'.xlsx';
        $writer->save('./static/fileds/'.$files);
        json_success_msg('https://desheng.hot68.cn/htqipei/htapi/public/static/fileds/'.$files);
    }

}
